//var info = require('../info.js');
var util = require('../../utils/util.js')
var app = getApp();
var md5 = require('../md5.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    showModal: false
  },
  delbyid: function (e) {
    var materialid = e.currentTarget.dataset.materialid
    this.setData({
     'materialid': materialid,
      showModal: true
    })
  },
  hide: function () {
    var that = this;
    this.setData({
      showModal: false
    })
  },
  go: function () {
    this.setData({
      showModal: false
    })
  },
  //底部导航跳转
  toAiIndex: function () {
    util.toAiIndex()
  },
  toContactsIng: function () {
    util.toContactsIng()
  },
  toProductRevision: function () {
    util.toProductRevision()
  },
  toMy: function () {
    util.toMy()
  },
  toBadge: function () {
    util.toBadge()
  },
  onPullDownRefresh: function(){
    wx.stopPullDownRefresh({
      complete: (res) => {},
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // 页面初始化 options为页面跳转所带来的参数 
    //设置语言0:中文，1：英文
    var setlanguage = wx.getStorageSync('setlanguage')
    if ((wx.getStorageSync('setlanguage') || !"".trim() == wx.getStorageSync('setlanguage'))) {
      this.setData({
        setlanguage: wx.getStorageSync('setlanguage')
      })
      if (setlanguage == 1) {
        wx.setNavigationBarTitle({
          title: 'Access to information list'
        })
      } else {
        wx.setNavigationBarTitle({
          title: '获取资料列表'
        })
      }
    } else {
      wx.setStorageSync('setlanguage', 0);
      this.setData({
        setlanguage: 0
      })
    }
    //获取缓存展会id和用户id存在则获取最新联系人列表
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=', exhibitionid)
    console.log('u=', u)
    if ((wx.getStorageSync('exhibitionid') || !"".trim() == wx.getStorageSync('exhibitionid'))
      && (wx.getStorageSync('u') || !"".trim() == wx.getStorageSync('u'))) {
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var cururl = app.globalData.picoaddress + '/attendee/materials/list'
      var m = {}
      m["v"] = '1.0.0'
      m["client"] = 'ios'
      m["timestamp"] = timestamp
      m["lan"] = 'cn'
      m["exhibitionid"] = exhibitionid
      // m["attendeeid"] = attendeeid
      m['sorttype'] = '1'
      //联系人id
      m["u"] = u
      var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'sorttype1timestamp' + timestamp + app.globalData.picotoken
      console.log(sign)
      var curb64 = md5.zhMD5(sign)
      console.log(curb64)
      m["sign"] = curb64
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: cururl,
        method: 'post',
        data: m,
        success(res) {
          console.log(res)
          var mesg = res.data
          console.log('mesg=' + mesg)
          var curdata = mesg.data

          that.setData({
            'zlmesgDetail': curdata
          });

        }, fail: res => {
          console.log(res, "error")
        }
      })

    } else {
      wx.redirectTo({
        url: '../signInbyPhone/signIn'
      })
    }
  },
  go: function (e) {
    var that = this;
    // 页面初始化 options为页面跳转所带来的参数 
    //获取缓存展会id和用户id存在则获取最新联系人列表
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=', exhibitionid)
    console.log('u=', u)
    var keyword = e.detail.value
    if ((wx.getStorageSync('exhibitionid') || !"".trim() == wx.getStorageSync('exhibitionid'))
      && (wx.getStorageSync('u') || !"".trim() == wx.getStorageSync('u'))) {
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var cururl = app.globalData.picoaddress + '/attendee/materials/list'
      var m = {}
      m["v"] = '1.0.0'
      m["client"] = 'ios'
      m["timestamp"] = timestamp
      m["lan"] = 'cn'
      m["exhibitionid"] = exhibitionid
      // m["attendeeid"] = attendeeid
      m['sorttype'] = '1'
      //联系人id
      m["u"] = u
      var sign = ''
      if(null!=keyword && ''!=keyword){
        m['keyword'] = keyword
        sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid +'keyword'+keyword+ 'sorttype1timestamp' + timestamp + app.globalData.picotoken
      }else{
        sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'sorttype1timestamp' + timestamp + app.globalData.picotoken
      }
      
      console.log(sign)
      var curb64 = md5.zhMD5(sign)
      console.log(curb64)
      m["sign"] = curb64
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: cururl,
        method: 'post',
        data: m,
        success(res) {
          console.log(res)
          var mesg = res.data
          console.log('mesg=' + mesg)
          var curdata = mesg.data

          that.setData({
            'zlmesgDetail': curdata
          });

        }, fail: res => {
          console.log(res, "error")
        }
      })

    } else {
      wx.redirectTo({
        url: '../signInbyPhone/signIn'
      })
    }

  },
  toReceiveInfolj(e) {
    console.log(e)
    var urlmesg = e.currentTarget.dataset.urlmesg
    wx.navigateTo({
      url: '../receiveInfo/receiveInfolj?urlmesg=' + urlmesg,
    })
  },
  delmesg: function (e) {
    var that = this
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    var materialid = that.data.materialid
    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000;
    var cururl = app.globalData.picoaddress + '/attendee/materials/del'
    var t = {}
    t["v"] = '1.0.0'
    t["client"] = 'ios'
    t["timestamp"] = timestamp
    t["lan"] = 'cn'
    t["exhibitionid"] = exhibitionid
    t["materialid"] = materialid
    t["u"] = u
    var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'materialid' + materialid + 'timestamp' + timestamp+ app.globalData.picotoken
    console.log(sign)
    var curb64 = md5.zhMD5(sign)
    console.log(curb64)
    t["sign"] = curb64
    wx.request({
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      url: cururl,
      method: 'post',
      data: t,
      success(res) {
        console.log(res)
        wx.redirectTo({
          url: '../receiveInfo/receiveInfo'
        })
      }, fail: res => {
        console.log(res, "error")
      }
    })
  },
  //滑动切换
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  //点击切换
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  }

})